﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FrasesSimpsonsMvc.Models;

namespace FrasesSimpsonsMvc.Controllers
{
    public class CapituloController : BaseController
    {

        public CapituloController() : base() { }

        public ActionResult Index()
        {
            var capitulos = from t in Context.Capitulos
                            select t;

            foreach (var capitulo in capitulos)
            {
                capitulo.LoadRelatedEntities();
            }

            return View(capitulos.ToList());
        }

        public ActionResult Detail(int? id)
        {
            if (!id.HasValue)
                return RedirectToAction("Index");

            var capitulo = (from t in Context.Capitulos
                            where t.Id == id.Value
                            select t).FirstOrDefault();

            if (capitulo == null)
                return RedirectToAction("Index");

            capitulo.LoadRelatedEntities(true);

            return View(capitulo);
        }

    }
}
